package com.chinackts.config;

import com.chinackts.config.interceptor.RequestInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author Lianhong
 * @since 2022/3/29
 */
@Configuration
public class CollectionRequestConfiguration implements WebMvcConfigurer {

    @Resource
    private RequestInterceptor requestInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(requestInterceptor);
        registration.addPathPatterns("/**");                      //所有路径都被拦截
        registration.excludePathPatterns(                         //添加不拦截路径
                "/**/init",             //初始化服务
                "/**/login",            //登录接口
                "/**/filestorage/**",   //文件存储
                "/**/swagger-resources/**",    //swagger
                "/**/swagger-ui/**",    //swagger
                "/**/v3/api-docs",      //swagger
                "/**/error"             //error
        );
    }
}
